home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / ScriptOMatic Lite.Dxr / 00014_ScriptParser.ls < prev    next >
Encoding:
Text File  |  1997-04-30  |  9.0 KB  |  200 lines

  1. property pParseScriptMember, pParseCastLibrary, pParseScriptText, pCommentRuns, pGlobalDeclarationRuns, pPropertyDeclarationRuns, pLocalDeclarationRuns, pHandlerDeclarationRuns, pPropertyVariableRuns, pGlobalVariableRuns, pLocalVariableRuns, pHandlerNameRuns, ppropertynamelist, pGlobalNameList, pLocalNameList, pHandlerNameList
  2.  
  3. on new me, scriptMember, castLibrary, scriptText, handlerNamelist
  4.   set the pParseScriptMember of me to scriptMember
  5.   set the pParseCastLibrary of me to castLibrary
  6.   set the pParseScriptText of me to scriptText
  7.   set the pHandlerNameList of me to handlerNamelist
  8.   sort(the pHandlerNameList of me)
  9.   initProperties(me)
  10.   return me
  11. end
  12.  
  13. on initProperties me
  14.   set the pCommentRuns of me to []
  15.   set the pGlobalDeclarationRuns of me to []
  16.   set the pPropertyDeclarationRuns of me to []
  17.   set the pLocalDeclarationRuns of me to []
  18.   set the pHandlerDeclarationRuns of me to []
  19.   set the pPropertyVariableRuns of me to []
  20.   set the pGlobalVariableRuns of me to []
  21.   set the pLocalVariableRuns of me to []
  22.   set the pHandlerNameRuns of me to []
  23.   set the ppropertynamelist of me to []
  24.   sort(the ppropertynamelist of me)
  25.   set the pGlobalNameList of me to []
  26.   sort(the pGlobalNameList of me)
  27.   set the pLocalNameList of me to []
  28.   sort(the pLocalNameList of me)
  29. end
  30.  
  31. on parseScript me, whichOptions
  32.   set scriptText to the pParseScriptText of me
  33.   set nextLineStartsAt to 1
  34.   repeat while scriptText <> EMPTY
  35.     set scriptLine to line 1 of scriptText
  36.     if word 1 of scriptLine starts "--" then
  37.       set continuationLines to 1
  38.       set continuationFlag to 1
  39.       repeat while continuationFlag = 1
  40.         case 1 of
  41.           (charToNum(the last char in scriptLine) = 194):
  42.             set continuationLines to continuationLines + 1
  43.             set scriptLine to line continuationLines of scriptText
  44.           (word 1 of line continuationLines + 1 of scriptText starts "--"):
  45.             set continuationLines to continuationLines + 1
  46.             set scriptLine to line continuationLines of scriptText
  47.           otherwise:
  48.             set continuationFlag to 0
  49.         end case
  50.       end repeat
  51.       set runLength to length(line 1 to continuationLines of scriptText)
  52.       set characterRunEnd to nextLineStartsAt + runLength - 1
  53.       add(the pCommentRuns of me, [nextLineStartsAt, characterRunEnd])
  54.       set nextLineStartsAt to characterRunEnd + 1
  55.       delete char 1 to runLength of scriptText
  56.       next repeat
  57.     end if
  58.     if scriptLine starts "end " then
  59.       set handlerName to word 2 of scriptLine
  60.       if handlerName <> EMPTY then
  61.         set characterRunStart to offset(handlerName, scriptLine) + nextLineStartsAt - 1
  62.         set characterRunEnd to characterRunStart + length(handlerName) - 1
  63.         add(the pHandlerDeclarationRuns of me, [characterRunStart, characterRunEnd])
  64.       end if
  65.       set scriptLineLength to length(scriptLine) + 1
  66.       set nextLineStartsAt to nextLineStartsAt + scriptLineLength
  67.       delete char 1 to scriptLineLength of scriptText
  68.       next repeat
  69.     end if
  70.     case word 1 of scriptLine of
  71.       "on":
  72.         set handlerName to word 2 of scriptLine
  73.         set characterRunStart to offset(handlerName, scriptLine) + nextLineStartsAt - 1
  74.         set characterRunEnd to characterRunStart + length(handlerName) - 1
  75.         add(the pHandlerDeclarationRuns of me, [characterRunStart, characterRunEnd])
  76.         set scriptLineLength to length(scriptLine) + 1
  77.         set elementList to elementsData(scriptLine)
  78.         deleteAt(elementList, 1)
  79.         deleteAt(elementList, 1)
  80.         set the pLocalNameList of me to []
  81.         repeat while count(elementList) > 0
  82.           set element to getPropAt(elementList, 1)
  83.           set elementSymbol to symbol(element)
  84.           set elementStartPos to getaProp(elementList, element)
  85.           deleteAt(elementList, 1)
  86.           add(the pLocalDeclarationRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  87.           if getOne(the pLocalNameList of me, elementSymbol) = 0 then
  88.             add(the pLocalNameList of me, elementSymbol)
  89.           end if
  90.         end repeat
  91.         set nextLineStartsAt to nextLineStartsAt + scriptLineLength
  92.         delete char 1 to scriptLineLength of scriptText
  93.         next repeat
  94.       "global":
  95.         set characterRunStart to offset("global", scriptLine) + nextLineStartsAt - 1
  96.         set characterRunEnd to characterRunStart + 5
  97.         add(the pGlobalDeclarationRuns of me, [characterRunStart, characterRunEnd])
  98.         set scriptLineLength to length(scriptLine) + 1
  99.         set nextLineStartsAt to nextLineStartsAt + scriptLineLength
  100.         delete word 1 of scriptLine
  101.         set totalItems to the number of items in scriptLine
  102.         repeat with theItem = 1 to totalItems
  103.           add(the pGlobalNameList of me, symbol(item theItem of scriptLine))
  104.         end repeat
  105.         delete char 1 to scriptLineLength of scriptText
  106.         next repeat
  107.       "property":
  108.         set characterRunStart to offset("property", scriptLine) + nextLineStartsAt - 1
  109.         set characterRunEnd to characterRunStart + 7
  110.         add(the pPropertyDeclarationRuns of me, [characterRunStart, characterRunEnd])
  111.         set scriptLineLength to length(scriptLine) + 1
  112.         set nextLineStartsAt to nextLineStartsAt + scriptLineLength
  113.         delete word 1 of scriptLine
  114.         set totalItems to the number of items in scriptLine
  115.         repeat with theItem = 1 to totalItems
  116.           add(the ppropertynamelist of me, symbol(item theItem of scriptLine))
  117.         end repeat
  118.         delete char 1 to scriptLineLength of scriptText
  119.         next repeat
  120.       otherwise:
  121.     end case
  122.     set elementList to elementsData(scriptLine)
  123.     set setFlag to 0
  124.     set putFlag to 0
  125.     set withFlag to 0
  126.     repeat while count(elementList) > 0
  127.       set element to getPropAt(elementList, 1)
  128.       set elementSymbol to symbol(element)
  129.       set elementStartPos to getaProp(elementList, element)
  130.       deleteAt(elementList, 1)
  131.       case 1 of
  132.         (getOne(the pLocalNameList of me, elementSymbol) > 0):
  133.           set setFlag to 0
  134.           set putFlag to 0
  135.           set withFlag to 0
  136.           add(the pLocalVariableRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  137.         (getOne(the pGlobalNameList of me, elementSymbol) > 0):
  138.           set setFlag to 0
  139.           set putFlag to 0
  140.           set withFlag to 0
  141.           add(the pGlobalVariableRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  142.         (getOne(the pHandlerNameList of me, elementSymbol) > 0):
  143.           set setFlag to 0
  144.           set putFlag to 0
  145.           set withFlag to 0
  146.           add(the pHandlerNameRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  147.         (getOne(the ppropertynamelist of me, elementSymbol) > 0):
  148.           set setFlag to 0
  149.           set putFlag to 0
  150.           set withFlag to 0
  151.           add(the pPropertyVariableRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  152.         setFlag:
  153.           set setFlag to 0
  154.           set putFlag to 0
  155.           set withFlag to 0
  156.           if element <> "the" then
  157.             add(the pLocalDeclarationRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  158.             if getOne(the pLocalNameList of me, elementSymbol) = 0 then
  159.               add(the pLocalNameList of me, elementSymbol)
  160.             end if
  161.           end if
  162.         putFlag:
  163.           set setFlag to 0
  164.           set putFlag to 0
  165.           set withFlag to 0
  166.           if getOne([#cast, #char, #field, #item, #line, #member, #castLib, #sprite, #word], elementSymbol) = 0 then
  167.             add(the pLocalDeclarationRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  168.             if getOne(the pLocalNameList of me, elementSymbol) = 0 then
  169.               add(the pLocalNameList of me, elementSymbol)
  170.             end if
  171.           end if
  172.         withFlag:
  173.           set setFlag to 0
  174.           set putFlag to 0
  175.           set withFlag to 0
  176.           add(the pLocalDeclarationRuns of me, [nextLineStartsAt + elementStartPos - 1, nextLineStartsAt + (elementStartPos + length(element) - 2)])
  177.           if getOne(the pLocalNameList of me, elementSymbol) = 0 then
  178.             add(the pLocalNameList of me, elementSymbol)
  179.           end if
  180.         (element = "set"):
  181.           set setFlag to 1
  182.           set putFlag to 0
  183.           set withFlag to 0
  184.         (getOne([#after, #before, #into], elementSymbol) > 0):
  185.           set setFlag to 0
  186.           set putFlag to 1
  187.           set withFlag to 0
  188.         (element = "with"):
  189.           set setFlag to 0
  190.           set putFlag to 0
  191.           set withFlag to 1
  192.       end case
  193.     end repeat
  194.     set scriptLineLength to length(scriptLine) + 1
  195.     set nextLineStartsAt to nextLineStartsAt + scriptLineLength
  196.     delete char 1 to scriptLineLength of scriptText
  197.   end repeat
  198.   nothing()
  199. end
  200.